package com.zhao.consumer;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * todo
 *
 * @author zhaoxing
 * @date 2022/5/17
 */
@Slf4j
@Service
@RocketMQMessageListener(topic = "test-topic-1", consumerGroup = "my-consumer_test-topic-1")
public class MyConsumer1 implements RocketMQListener<String> {

    /**
     *需要注意的是，onMessage（）封装了ACK机制，消费者往外抛异常时，RocketMQ认为消费失败，重新发送该条消息，否则默认消费成功
     */
    @SneakyThrows
    @Override
    public void onMessage(String message) {
        //log.info("receivie message:topic={},body={}", message.getTopic(), new String(message.getBody()));
        log.info("receivie message:topic={}", message);
    }
}

@Data
@AllArgsConstructor
class OrderPaidEvent implements Serializable {

    private String orderId;

    private Integer paidMoney;
}
